import { RowDataPacket } from "mysql2";
import connection from "../app/database";

class authService {
  async checkPermission(tableName: string, id: number, userId: number) {
    try {
      const statement = `SELECT * FROM ${tableName} WHERE id = ? AND user_id = ?;`;
      const [rows] = await connection.execute<RowDataPacket[]>(statement, [
        id,
        userId,
      ]);
      return rows.length === 0 ? false : true;
    } catch (error) {
      console.log(error);
    }
  }
}

export default new authService();
